import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model 可执行定义
 * @date: 2018-9-7


 */
import { getResponse, createPagination } from 'utils/utils';
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { fetchExecutable as _fetchExecutable, createExecutable as _createExecutable, updateExecutable as _updateExecutable, deleteHeader as _deleteHeader, fetchExecutableDetail as _fetchExecutableDetail, executorConfig as _executorConfig, executorConfigByExecutable as _executorConfigByExecutable } from "../services/executableService";
export default {
  namespace: 'executable',
  state: {
    groupsList: [],
    // 执行器列表
    executableList: [],
    // 列表数据
    executableDetail: {},
    // 详情数据
    modalVisible: false,
    // 控制模态框显示
    pagination: {},
    // 分页信息对象
    exeTypeList: [],
    // 可执行类型
    executorStrategyList: [],
    // 执行器策略
    failStrategyList: [],
    // 失败处理策略
    executorConfigList: [] // 执行器配置列表

  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_, _ref) {
      var call, put, res, exeTypeList, executorStrategyList, failStrategyList;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryMapIdpValue, {
                exeTypeList: 'CSDR.GLUE_TYPE',
                executorStrategyList: 'CSDR.EXECUTOR_STRATEGY',
                failStrategyList: 'CSDR.FAIL_STRATEGY'
              });

            case 4:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);
              exeTypeList = res.exeTypeList, executorStrategyList = res.executorStrategyList, failStrategyList = res.failStrategyList;

              if (!res) {
                _context.next = 10;
                break;
              }

              _context.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  exeTypeList: exeTypeList,
                  executorStrategyList: executorStrategyList,
                  failStrategyList: failStrategyList
                }
              });

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    fetchExecutable: /*#__PURE__*/_regeneratorRuntime.mark(function fetchExecutable(_ref2, _ref3) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchExecutable$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _context2.next = 4;
              return call(_fetchExecutable, payload);

            case 4:
              res = _context2.sent;
              list = getResponse(res);

              if (!list) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  executableList: list.content,
                  // list.content
                  pagination: createPagination(list)
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchExecutable);
    }),
    // 查询job详情
    fetchExecutableDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchExecutableDetail(_ref4, _ref5) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchExecutableDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call, put = _ref5.put;
              _context3.next = 4;
              return call(_fetchExecutableDetail, payload);

            case 4:
              res = _context3.sent;
              result = getResponse(res);

              if (!result) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  executableDetail: result
                }
              });

            case 9:
              return _context3.abrupt("return", result);

            case 10:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchExecutableDetail);
    }),
    // 创建
    createExecutable: /*#__PURE__*/_regeneratorRuntime.mark(function createExecutable(_ref6, _ref7) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createExecutable$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              call = _ref7.call;
              _context4.next = 4;
              return call(_createExecutable, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, createExecutable);
    }),
    // 更新
    updateExecutable: /*#__PURE__*/_regeneratorRuntime.mark(function updateExecutable(_ref8, _ref9) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateExecutable$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              call = _ref9.call;
              _context5.next = 4;
              return call(_updateExecutable, payload);

            case 4:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, updateExecutable);
    }),
    // 删除头
    deleteHeader: /*#__PURE__*/_regeneratorRuntime.mark(function deleteHeader(_ref10, _ref11) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function deleteHeader$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              call = _ref11.call;
              _context6.next = 4;
              return call(_deleteHeader, _objectSpread({}, payload));

            case 4:
              result = _context6.sent;
              return _context6.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, deleteHeader);
    }),
    // 执行器配置列表
    executorConfig: /*#__PURE__*/_regeneratorRuntime.mark(function executorConfig(_ref12, _ref13) {
      var payload, call, put, result, res;
      return _regeneratorRuntime.wrap(function executorConfig$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call, put = _ref13.put;
              _context7.next = 4;
              return call(_executorConfig, payload);

            case 4:
              result = _context7.sent;
              res = getResponse(result);

              if (!res) {
                _context7.next = 9;
                break;
              }

              _context7.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  executorConfigList: res
                }
              });

            case 9:
            case "end":
              return _context7.stop();
          }
        }
      }, executorConfig);
    }),
    // 执行器配置列表
    executorConfigByExecutable: /*#__PURE__*/_regeneratorRuntime.mark(function executorConfigByExecutable(_ref14, _ref15) {
      var payload, call, result, res;
      return _regeneratorRuntime.wrap(function executorConfigByExecutable$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              call = _ref15.call;
              _context8.next = 4;
              return call(_executorConfigByExecutable, payload);

            case 4:
              result = _context8.sent;
              res = getResponse(result);
              return _context8.abrupt("return", res);

            case 7:
            case "end":
              return _context8.stop();
          }
        }
      }, executorConfigByExecutable);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref16) {
      var payload = _ref16.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};